#include "FlameJet.h"

#include "FlameJetBox.h"
#include "Camera.h"
#include "EmitterManager.h"

#include "ObjectManager.h"

FlameJet::FlameJet(void)
{
	fireDelay = 1.0f;
	fireTime = 0.0f;
	fireCollBox = new FlameJetBox();
	isFiring = false;
	flameEmitter = EmitterManager::GetInstance()->GetEmitter("flameJet");
	flameEmitter->SetPosX(positionX);
	flameEmitter->SetPosY(positionY - 3.0f);

	ObjectManager::GetInstance()->AddObject(1,fireCollBox);
}


FlameJet::~FlameJet(void)
{
}


void FlameJet::Update(float deltaTime)
{
	//Update Emitter
	flameEmitter->SetPosX(positionX);
	flameEmitter->SetPosY(positionY - 3.0f);

	//Update coll Box
	RECT collHitBox = {(LONG)(positionX - 5.0f), (LONG)(positionX + 5.0f), (LONG)(positionY- 100.0f), (LONG)(positionY)};
	fireCollBox->UpdateCollBox(collHitBox);


	if(!isFiring)
	{
		fireDelay -= deltaTime;
		if(fireDelay <= 0)
		{
			fireTime = 2.0f;
			isFiring = true;
			fireCollBox->SetActive(true);
			if(flameEmitter != nullptr)
				flameEmitter->SetActive(true);
		}
	}
	else
	{
		fireTime -= deltaTime;
		if(fireTime <= 0)
		{
			fireDelay = 1.0f;
			isFiring = false;
			fireCollBox->SetActive(false);
			if(flameEmitter != nullptr)
				flameEmitter->SetActive(false);
		}
		if(flameEmitter != nullptr)
		{
			flameEmitter->Update(deltaTime);
		}
	}
}
void FlameJet::Render(void) const
{
	if(imageID != -1)
	{
		CSGD_TextureManager::GetInstance()->Draw(imageID, 
			(int)(positionX - Camera::GetInstance()->OffsetX()),
			(int)(positionY - Camera::GetInstance()->OffsetY()));
	}
	if(isFiring)
	{
		if(flameEmitter != nullptr)
		{
			flameEmitter->Render();
		}
	}

}
void FlameJet::HandleCollision(GameObject& other, CollisionInfo& info)
{

}